package com.example.nettydemo.demos;

import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class TestMyBuffer {

    public static void main(String[] args) {

        try {
            FileChannel channel = new FileInputStream("data.txt").getChannel();

            //设置缓冲区大小
            ByteBuffer buffer = ByteBuffer.allocate(10);
            //从channel读取数据，向buffer中写入
            channel.read(buffer);

            //切换只读模式
            buffer.flip();

            //无法读取文件所有内容
            while (buffer.hasRemaining()) {
                System.out.print((char) buffer.get());
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }


    }
}
